package com.ymatou.iapi.dguser.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.dguser.parameter.GetUserBindInfoBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.GetUserBindInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.database.model.DGThirdPartyBindInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;
/**
*查询微信绑定信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserBindInfo{
	private static GetUserBindInfoBean getuserbindinfoBean;
	private static GetUserBindInfoCall getuserbindinfoCall;
	DGUserWapper DGUserWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询微信绑定信息");
	}

	@Before
	public void caseUp() {
		getuserbindinfoBean=new GetUserBindInfoBean();
		getuserbindinfoCall=new GetUserBindInfoCall();
		DGUserWapper=new DGUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserbindinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDB(String openId) {
		DGThirdPartyBindInfo dgThirdPartyBindInfo = DGUserWapper.selectDGThirdPartyOpenId(openId).get(0);
		JsonObject jet = getuserbindinfoCall.getJsonObject().get("userBindDtos").getAsJsonArray().get(0).getAsJsonObject();
		Logger.verifyEquals(jet.get("bindId").getAsInt(),dgThirdPartyBindInfo.getBindId(),"验证bindId");
		Logger.verifyEquals(jet.get("userType").getAsInt(),dgThirdPartyBindInfo.getUserType(),"验证userType");
		Logger.verifyEquals(jet.get("thirdPartyType").getAsInt(),dgThirdPartyBindInfo.getThirdPartyType(),"验证thirdPartyType");
		Logger.verifyEquals(jet.get("appSource").getAsInt(),dgThirdPartyBindInfo.getAppSource(),"验证appSource");
		Logger.verifyEquals(jet.get("unionId").getAsString(),dgThirdPartyBindInfo.getUnionId(),"验证unionId");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserBindInfo_001() {
		Logger.start(true,"查询微信绑定信息查询成功");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			getuserbindinfoBean.setUserId(userId);
			getuserbindinfoCall.setData(getuserbindinfoBean);
			getuserbindinfoCall.callService();			
			Logger.verifyEquals("true", getuserbindinfoCall.getString("success"), "验证success");
			verifyDB(usercreateBean.getOpenId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserBindInfo_002() {
		Logger.start(true,"查询微信绑定信息查询成功-seller");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initSellerUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			getuserbindinfoBean.setUserId(userId);
			getuserbindinfoCall.setData(getuserbindinfoBean);
			getuserbindinfoCall.callService();			
			Logger.verifyEquals("true", getuserbindinfoCall.getString("success"), "验证success");
			verifyDB(usercreateBean.getOpenId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserBindInfo_003() {
		Logger.start(true,"查询微信绑定信息查询成功-sellercs");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initCsUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			getuserbindinfoBean.setUserId(userId);
			getuserbindinfoCall.setData(getuserbindinfoBean);
			getuserbindinfoCall.callService();			
			Logger.verifyEquals("true", getuserbindinfoCall.getString("success"), "验证success");
			verifyDB(usercreateBean.getOpenId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserBindInfo_004() {
		Logger.start(true,"查询微信绑定信息查询成功-独立app");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			usercreateBean.setAppSource(DGUserCallService.DG_SellerWxApp);
			usercreateBean.setWxAppName(DGUserCallService.TestWxsqOther);
			usercreateBean.setBelongSellerId(DGUserCallService.TestWxsqOtherSellerId);
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			getuserbindinfoBean.setUserId(userId);
			getuserbindinfoCall.setData(getuserbindinfoBean);
			getuserbindinfoCall.callService();			
			Logger.verifyEquals("true", getuserbindinfoCall.getString("success"), "验证success");
			verifyDB(usercreateBean.getOpenId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserBindInfo_005() {
		Logger.start(true,"不输入userid，不返还数据");
		try {
			getuserbindinfoCall.setData(getuserbindinfoBean);
			getuserbindinfoCall.callService();			
			Logger.verifyEquals("true", getuserbindinfoCall.getString("success"), "验证success");
			Logger.verifyEquals(0, getuserbindinfoCall.getJsonObject().get("userBindDtos").getAsJsonArray().size(), "验证userBindDtos");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserBindInfo_006() {
		Logger.start(true,"userid不存在，不返还数据");
		try {
			getuserbindinfoBean.setUserId(100);
			getuserbindinfoCall.setData(getuserbindinfoBean);
			getuserbindinfoCall.callService();			
			Logger.verifyEquals("true", getuserbindinfoCall.getString("success"), "验证success");
			Logger.verifyEquals(0, getuserbindinfoCall.getJsonObject().get("userBindDtos").getAsJsonArray().size(), "验证userBindDtos");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}